# Table 4: Effect of Proposition Net Benefit and Ballot Position on Selective Abstention


# 1. Load Packages ----

library(lfe)
library(stargazer)
library(haven)

# 2. Read in Data ----

load(file = "df_voxit_individual_props.RData")

# 3. Conduct Regressions ----
# standardize net benefit and proposition ranking
voxit_propositions$utility_optc1_norm <- 
  (voxit_propositions$utility_optc - 
     mean(voxit_propositions[voxit_propositions$turnout==1,]$utility_optc))/
  sd(voxit_propositions[voxit_propositions$turnout==1,]$utility_optc)

voxit_propositions$prop_nr_day_norm <- 
  (voxit_propositions$prop_nr_day -
     mean(voxit_propositions[voxit_propositions$turnout==1,]$prop_nr_day))/
  sd(voxit_propositions[voxit_propositions$turnout==1,]$prop_nr_day)


# reg1
lm.eb_fe <- felm(empty_ballot ~ utility_optc + prop_nr_day | 
                   haven::as_factor(typex) * factor(datum_merge) + canton_id | 0 | id + datum_merge, 
                 data = voxit_propositions[voxit_propositions$turnout==1,])
summary(lm.eb_fe)

lm.eb_fe_norm <- felm(empty_ballot ~ utility_optc1_norm + prop_nr_day_norm | 
                        haven::as_factor(typex) * factor(datum_merge) + canton_id | 0 | id + datum_merge, 
                      data = voxit_propositions[voxit_propositions$turnout==1,])
summary(lm.eb_fe_norm)

# reg2
lm.eb_fec <- felm(empty_ballot ~ utility_optc + prop_nr_day + 
                    male + married + age + uni + knowledge + leftright | 
                    haven::as_factor(typex) * factor(datum_merge) + canton_id | 0 | id + datum_merge, 
                  data = voxit_propositions[voxit_propositions$turnout==1,])
summary(lm.eb_fec)

lm.eb_fec_norm <- felm(empty_ballot ~ utility_optc1_norm + prop_nr_day_norm +
                         male + married + age + uni + knowledge + leftright| 
                         haven::as_factor(typex) * factor(datum_merge) + canton_id | 0 | id + datum_merge, 
                       data = voxit_propositions[voxit_propositions$turnout==1,])
summary(lm.eb_fec_norm)

# one std
sd(voxit_propositions[voxit_propositions$turnout==1,]$utility_optc)
sd(voxit_propositions[voxit_propositions$turnout==1,]$prop_nr_day)

# 4. Regression tables ----
# Non-Standardized Coefficients
stargazer(lm.eb_fe, lm.eb_fec,
          type = "latex", star.cutoffs = c(0.1, 0.05, 0.01),
          star.char = c("*", "**", "***"),
          summary=T, df = F, float = F,
          keep = c("^utility_optc", "prop_nr_day"),
          covariate.labels = c("Net benefit U_{ij}", "Ballot position"),
          dep.var.caption="Dependent variable: Selective abstention",
          add.lines = list(c("Controls", "No", "Yes"),
                           c("Canton FE", "Yes", "Yes"),
                           c("Voting day FE", "Yes", "Yes"),
                           c("Legal Form FE", "Yes", "Yes"),
                           c("Voting day \\times", "", "", ""),
                           c("Legal form FE", "Yes", "Yes")),
          dep.var.labels.include=F,
          omit.table.layout ="n",
          keep.stat = c("n"),
          out = "Table4A.tex")

# Standardized Coefficients
stargazer(lm.eb_fe_norm, lm.eb_fec_norm,
          type = "latex", star.cutoffs = c(0.1, 0.05, 0.01),
          star.char = c("*", "**", "***"),
          summary=T, df = F, float = F,
          keep = c("^utility_optc", "^prop_nr_day"),
          covariate.labels = c("Net benefit U_{ij}", "Ballot position"),
          dep.var.caption="Dependent variable: Selective abstention",
          add.lines = list(c("Controls", "No", "Yes"),
                           c("Canton FE", "Yes", "Yes"),
                           c("Voting day FE", "Yes", "Yes"),
                           c("Legal Form FE", "Yes", "Yes"),
                           c("Voting day \\times", "", "", ""),
                           c("Legal form FE", "Yes", "Yes")),
          dep.var.labels.include=F,
          omit.table.layout ="n",
          keep.stat = c("n"),
          out = "Table4B.tex")

